package com.example.springboot.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description: Aop记录日志
 * @Author wenlinyu
 * @Date: 2020/12/21 14:52
 * @Version 1.0
 */
@Component
@Aspect
public class LogAspect {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 切入点表达式
     */
    @Pointcut("within(com.example.springboot.controller..*)")
    public void logAspect() {

    }

    /**
     * 切入点之前执行
     * @param joinpoint
     */
    @Before("logAspect()")
    public void doBefore(JoinPoint joinpoint) {
        logger.info("访问时间：{}--访问接口：{}", new Date(), joinpoint.getSignature());
    }
}
